package com.kaibes.admin.login;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.kaibes.web.api.ApiLink;
import com.kaibes.web.encryption.EncryptionUtils;
import com.kaibes.web.prefix.PrefixController;
import com.kaibes.web.thymeleaf.ThymeleafConfig;
import com.kaibes.web.util.ControllerUtils;

@PrefixController
@RequestMapping("/admin")
public class LoginController implements InitializingBean {

    @Autowired
    private EncryptionUtils encryptionUtils;
    @Autowired
    private ThymeleafConfig thymeleafConfig;

    @GetMapping("login")
    @ApiLink(value = "用户登录界面", validated = false)
    public String login(@RequestAttribute(required = false) Integer userId) {
        if (userId != null) {
            return ControllerUtils.redirect("/admin/index");
        }
        return "login";
    }

	@Override
	public void afterPropertiesSet() throws Exception {
		thymeleafConfig.putStaticVariable("encryptionUtils", encryptionUtils);
	}

}
